package com.favccxx.search.infrastructure.exception;

import com.favccxx.search.infrastructure.util.rest.RestResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.List;
import java.util.Set;

/**
 * @author favccxx
 */
@Slf4j
@RestControllerAdvice
public class AppExceptionHandler {

    @ExceptionHandler(value = AppException.class)
    public RestResult<AppException> handleAppException(AppException appException) {
        log.error("Warning!!! " + appException.getErrorCode() + " : " + appException.getErrorMessage(), appException);
        return RestResult.error(appException.getErrorCode(), appException.getErrorMessage());
    }


}
